package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.List;

import com.xcity.db.entity.Player;
import com.xcity.game.combat.attr.CombatAttribute;
import com.xcity.game.employee.EmployeeService;
import com.xcity.game.employee.config.impl.EmployeeQualityLevelUpConfigure.QualityUpgradable;
import com.xcity.game.employee.response.EmployeeLevelUpRequired;
import com.xcity.game.employee.template.EmployeeQualityUpTemplate;
import com.xcity.game.item.ItemInfo;
import com.xcity.pomelo.request.EmployeeQualityLevelUpRequest;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class EmployeeQualityUpResponse extends Response {
	
	private long id;
	private int qualityLvl; // 品级
	private short[] attrsIndex; // 影响属性
	private Object[] attrs;
	private NextLvlRequired next;
	
	public static class NextLvlRequired { // 下一品级需求
		public int levelLimit;
		public List<ItemInfo> items;
		public long gold;
	}
	
	public EmployeeQualityUpResponse(EmployeeQualityLevelUpRequest req, Player player, QualityUpgradable unit, EmployeeQualityUpTemplate template, EmployeeService service) {
		super(req.getSerial());
		this.id = req.getId();
		this.qualityLvl = unit.getQualityLevel();
		CombatAttribute[] growthAttrs = template.getAttributes();
		this.attrsIndex = new short[growthAttrs.length];
		this.attrs = new Object[growthAttrs.length];
		for (int i = 0; i < growthAttrs.length; i++) {
			CombatAttribute refer = growthAttrs[i];
			this.attrsIndex[i] = (short) refer.getType().ordinal();
			this.attrs[i] = refer.format(unit.getAttributeValue(refer.getType()));
		}
		EmployeeQualityUpTemplate nextTemplate = service.configure().getQualityLevelUpConfigure().getNextLevelTemplate(unit);
		if (nextTemplate != null) {
			next = new NextLvlRequired();
			next.levelLimit = nextTemplate.getLevelLimit();
			ItemInfo[] refers = template.getWrappedItems();
			next.items = new ArrayList<ItemInfo>(refers.length);
			for (ItemInfo refer : refers) {
				next.items.add(new EmployeeLevelUpRequired(refer, player));
			}
			next.gold = nextTemplate.getGold();
		}
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public int getQualityLvl() {
		return qualityLvl;
	}

	public void setQualityLvl(int qualityLvl) {
		this.qualityLvl = qualityLvl;
	}

	public short[] getAttrsIndex() {
		return attrsIndex;
	}

	public void setAttrsIndex(short[] attrsIndex) {
		this.attrsIndex = attrsIndex;
	}

	public Object[] getAttrs() {
		return attrs;
	}

	public void setAttrs(Object[] attrs) {
		this.attrs = attrs;
	}

	public NextLvlRequired getNext() {
		return next;
	}

	public void setNext(NextLvlRequired next) {
		this.next = next;
	}
	
}
